package com.jinmdz.fmis.dao.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 冷藏Provider
 *
 * @author LiCongLu
 * @date 2020-02-16 15:51
 */
public class ColdStorageProvider {

    /**
     * 按照主键查询冷藏信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-20 14:52
     */
    public String getColdStorageViewById(@Param("id") Integer id) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" cold_storage.id,business_code,cold_storage.equipment_type_code,equipment_id");
                builder.append(" ,appointment_in_time,appointment_out_time,reality_in_time,reality_out_time");
                builder.append(" ,process_state_code,rule_number,rule_unit,rule_code,rule_remark,cold_storage.remark ");
                builder.append(" ,random_code,charge_id,cold_storage.version ");
                builder.append(" ,cold_storage_equipment.equipment_code ");
                SELECT(builder.toString());
                FROM(" cold_storage ");
                LEFT_OUTER_JOIN(" cold_storage_equipment on cold_storage_equipment.id = cold_storage.equipment_id  ");
                WHERE(" cold_storage.deleted = 0 ");
                WHERE(" cold_storage.id = #{id} ");
                ORDER_BY(" cold_storage.id limit 1 ");
            }
        }.toString();
    }

    /**
     * 按照业务编码查询冷藏信息
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-16 15:51
     */
    public String listColdStorageViewByBusinessCode(@Param("businessCode") String businessCode) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" cold_storage.id,business_code,cold_storage.equipment_type_code,equipment_id");
                builder.append(" ,appointment_in_time,appointment_out_time,reality_in_time,reality_out_time");
                builder.append(" ,process_state_code,rule_number,rule_unit,rule_code,rule_remark,cold_storage.remark ");
                builder.append(" ,random_code,charge_id,cold_storage.version ");
                builder.append(" ,cold_storage_equipment.equipment_code ");
                SELECT(builder.toString());
                FROM(" cold_storage ");
                LEFT_OUTER_JOIN(" cold_storage_equipment on cold_storage_equipment.id = cold_storage.equipment_id  ");
                WHERE(" cold_storage.deleted = 0 ");
                WHERE(" cold_storage.business_code = #{businessCode} ");
                ORDER_BY(" cold_storage.id ");
            }
        }.toString();
    }
}
